package com.hll.javaweb.servlet.cookie;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author hll
 * @create 2022-05-10 13:54
 */
@WebServlet("/cookie-read")
public class CookieRead extends HttpServlet {
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    Cookie[] cookies = req.getCookies();
    // 也可以获取到 cookie后，cookie.setValue , 并 resp.addCookie 重新设置
    for (Cookie cookie : cookies) {
      // getName方法返回Cookie的key（名）
      // getValue方法返回Cookie的value值
      resp.getWriter().write(cookie.getName() + "=" + cookie.getValue() + "\n");
    }
  }
}
